package org.dangran;

import cn.hutool.core.util.IdUtil;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Test {
    public static void main(String[] args) throws Exception {
        System.out.println(IdUtil.simpleUUID());

        List<String> list = new ArrayList<>();
        Collections.addAll(list, "a", "aa", "ab", "aabb", "abb", "aab");
        System.out.println(list);   //[a, aa, ab, aabb, abb, aab]
        list.removeIf(l -> l.equals("a"));    //java 8
        System.out.println(list);   //[aa, ab, aabb, abb, aab]
        String join = String.join(",", list);
        System.out.println(join);  //aa,ab,aabb,abb,aab
        list.add(0, "ccc");
        System.out.println(list);//[ccc, aa, ab, aabb, abb, aab]



        /*
            时间日期
        */
        System.out.println("================时间日期================");
        Date start = new Date(1727163159563L);
        Date date = new Date();
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        String format = new SimpleDateFormat("yyyyMMdd").format(date);
        System.out.println("今年：" + (date.getYear() + 1900));//今年：2024
        System.out.println("LocalDateTime.getYear()" + now.getYear());//2024
        System.out.println(date + "---" + date.getTime() + "---差值:" + (date.getTime() - start.getTime()));//Thu Oct 10 15:50:26 CST 2024---1728546626437---差值:1383466874
        System.out.println("date 转 localDateTime: " + localDateTime);//date 转 localDateTime: 2024-10-10T15:50:26.437
        System.out.println(format);//20241010
        LocalDateTime localDateTime1 = now.withHour(10).withMinute(0).withSecond(0).withNano(0);
        System.out.println(localDateTime1);//2025-10-10T10:00
        System.out.println(now);//2025-05-26T13:57:10.897466700
        String format1 = now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        System.out.println("format1:"+format1);//format1:2025-10-20T14:32:17.359629
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format2 = now.format(formatter);
        System.out.println("format2: "+format2);//format2: 2025-10-20 14:32:17

        /*
            BigDecimal
        */
        System.out.println("================BigDecimal================");
        String aaa = "123456789.5423015321";
        String bbbaaa = "132456789.5453454545";
        BigDecimal bigDecimal = new BigDecimal(aaa);
        BigDecimal bigDecimal1 = new BigDecimal(bbbaaa);
        //用静态方法时，超过long类型长度，会报错
        //BigDecimal bigDecimal = BigDecimal.valueOf(Long.parseLong(aaa));
        BigDecimal divide = bigDecimal.divide(BigDecimal.valueOf(10000), MathContext.UNLIMITED);
        System.out.println(bigDecimal + "-->" + divide);//123456789.000000000-->12345.678900000
        //换算百分比
        BigDecimal divide1 = bigDecimal.divide(bigDecimal1, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        System.out.println("divide1-" + divide1);//divide1-93.00

        /*
            Stream
         */
        System.out.println("================Stream================");
        List<Integer> arrlist = Arrays.asList(7, 6, 9, 4, 11, 6);
        // 自然排序
        Optional<Integer> max = arrlist.stream().max(Integer::compareTo);
        // 自定义排序（从大到小排序）
        Optional<Integer> max2 = arrlist.stream().max((o1, o2) -> o2 - o1);
        System.out.println("自然排序的最大值：" + max.get());//自然排序的最大值：11
        System.out.println("自定义排序的最大值：" + max2.get());//自定义排序的最大值：4
        List<Integer> list1 = arrlist.stream().filter(e -> e == 7).toList();
        System.out.println(list1);


        HashMap<String, String> map = new HashMap<>();
        map.put("a","1");
        map.put("b","2");
        String s = map.get(null);
        System.out.println(s);

        //提交测试 head~1



    }
}
